home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / fl_overlay_visual.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  3.2 KB  |  104 lines

  1. //
  2. // "$Id: fl_overlay_visual.cxx,v 1.4 1999/01/07 19:17:40 mike Exp $"
  3. //
  4. // X overlay support for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Return an overlay visual, if any.  Also allocate a colormap and
  27. // record the depth for fl_color() to use.
  28. // Another disgusting X interface, based on code extracted and
  29. // purified with great difficulty from XLayerUtil.C:
  30.  
  31. #include <config.h>
  32. #if HAVE_OVERLAY
  33. #include <FL/Fl.H>
  34. #include <FL/x.H>
  35.  
  36. // SERVER_OVERLAY_VISUALS property element:
  37. struct OverlayInfo {
  38.   long overlay_visual;
  39.   long transparent_type;
  40.   long value;
  41.   long layer;
  42. };
  43.  
  44. extern Colormap fl_overlay_colormap;
  45. extern XVisualInfo* fl_overlay_visual;
  46. extern ulong fl_transparent_pixel;
  47.  
  48. XVisualInfo *fl_find_overlay_visual() {
  49.   static char beenhere;
  50.   if (beenhere) return fl_overlay_visual;
  51.   beenhere = 1;
  52.  
  53.   fl_open_display();
  54.   Atom overlayVisualsAtom =
  55.     XInternAtom(fl_display,"SERVER_OVERLAY_VISUALS",1);
  56.   if (!overlayVisualsAtom) return 0;
  57.   OverlayInfo *overlayInfo;
  58.   ulong sizeData, bytesLeft;
  59.   Atom actualType;
  60.   int actualFormat;
  61.   if (XGetWindowProperty(fl_display, RootWindow(fl_display, fl_screen),
  62.              overlayVisualsAtom, 0L, 10000L, False,
  63.              overlayVisualsAtom, &actualType, &actualFormat,
  64.              &sizeData, &bytesLeft,
  65.              (unsigned char **) &overlayInfo)) return 0;
  66.  
  67.   if (actualType == overlayVisualsAtom && actualFormat == 32) {
  68.     int n = int(sizeData/4);
  69.     XVisualInfo* v = 0;
  70.     // find the greatest depth that has a transparent pixel:
  71.     for (int i = 0; i < n; i++) {
  72.       if (overlayInfo[i].transparent_type != 1) continue;
  73.       if (overlayInfo[i].layer <= 0) continue;
  74.       XVisualInfo templt;
  75.       templt.visualid = overlayInfo[i].overlay_visual;
  76.       int num;
  77.       XVisualInfo *v1=XGetVisualInfo(fl_display, VisualIDMask, &templt, &num);
  78.       if (v1->screen == fl_screen && 
  79.       !v1->red_mask && (!v || v1->depth >= v->depth && v1->depth <= 8)) {
  80.     if (v) XFree((char*)v);
  81.     v = v1;
  82.     fl_transparent_pixel = overlayInfo[i].value;
  83.       } else {
  84.     XFree((char*)v1);
  85.       }
  86.     }
  87.     if (v) {
  88.       fl_overlay_visual = v;
  89.       fl_overlay_colormap = 
  90.     XCreateColormap(fl_display, RootWindow(fl_display, fl_screen),
  91.             v->visual, AllocNone);
  92.     }
  93.   }
  94.   XFree((char*)overlayInfo);
  95.   //  printf("overlay visual %d selected\n", fl_overlay_visual->visualid);
  96.   return fl_overlay_visual;
  97. }
  98.  
  99. #endif
  100.  
  101. //
  102. // End of "$Id: fl_overlay_visual.cxx,v 1.4 1999/01/07 19:17:40 mike Exp $".
  103. //
  104.